package com.kbook.action.impl;

import java.util.Map;

import com.kbook.action.Action;
import com.kbook.bean.UserBean;


public abstract class AbstractAction implements Action {

	
	/**
	 * 判断用户是否拥有权限执行该动作
	 * @param user 用户
	 * @param params 参数map
	 * @return
	 */
	protected boolean hasPower(UserBean user, Map params) {
		return true;
	}
	
	/* (non-Javadoc)
	 * @see com.kbook.action.Action#excute(com.kbook.bean.UserBean, java.util.Map)
	 */
	public Object excute(UserBean user, Map params) throws Exception {
		// TODO Auto-generated method stub
		Object obj = null;
		//判断用户是否拥有权限执行该动作
		if(hasPower(user, params)){
			obj = doAction(user, params);
		}
		
		afterAction(obj, user, params);
		
		return obj;
	}

	/**
	 * 动作后的操作
	 * @param obj 动作后的返回结果
	 * @param user 执行该操作的用户
	 * @param params 客户端传递的参数
	 * @return
	 */
	protected void afterAction(Object obj, UserBean user, Map params){
	}
	
	/**
	 * 执行动作的具体实现
	 * @param user 执行该操作的用户
	 * @param params 客户端传递的参数
	 * @return
	 * @throws Exception 
	 */
	protected abstract Object doAction(UserBean user, Map params) throws Exception;
}
